﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace TLSharp
{
    public class BrowseMyGameResponse
    {
        public string MessageType = "";
        public List<string> ActiveGames = new List<string>();
        public List<string> WaitingGames = new List<string>();
        public List<string> Results = new List<string>();
        public List<string> Requests = new List<string>();
        public List<string> Challenges = new List<string>();
        public int ThisTeamID = -1;
        public double CurrentRank = 0;
        public int ErrorCode;
        public string UserMessage;


        private List<Game> _ActiveGamesObjects = null;
        private List<Game> _WaitingGamesObjects = null;
        private List<Game> _ResultObjects = null;
        private List<GameRequest> _RequestObjects = null;
        private List<GameRequest> _ChallengeObjects = null;

        public List<Game> ActiveGamesObjects
        {
            get
            {
                if (_ActiveGamesObjects == null && (ActiveGames != null && ActiveGames.Count > 0))
                {
                    _ActiveGamesObjects = new List<Game>();
                    foreach (string ThisString in ActiveGames)
                    {
                        Newtonsoft.Json.Linq.JObject o = JObject.Parse(ThisString);

                        Game b = (Game)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(Game));

                        JValue ThisValue = new JValue(ThisString);
                        _ActiveGamesObjects.Add(b);
                    }
                }
                return _ActiveGamesObjects;
            }
        }

        public List<Game> WaitingGamesObjects
        {
            get
            {
                if (_WaitingGamesObjects == null && (WaitingGames != null && WaitingGames.Count > 0))
                {
                    _WaitingGamesObjects = new List<Game>();
                    foreach (string ThisString in WaitingGames)
                    {
                        Newtonsoft.Json.Linq.JObject o = JObject.Parse(ThisString);

                        Game b = (Game)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(Game));

                        JValue ThisValue = new JValue(ThisString);
                        _WaitingGamesObjects.Add(b);
                    }
                }
                return _WaitingGamesObjects;
            }
        }

        public List<Game> ResultObjects
        {
            get
            {
                if (_ResultObjects == null && (Results != null && Results.Count > 0))
                {
                    _ResultObjects = new List<Game>();
                    foreach (string ThisString in Results)
                    {
                        Newtonsoft.Json.Linq.JObject o = JObject.Parse(ThisString);

                        Game b = (Game)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(Game));

                        JValue ThisValue = new JValue(ThisString);
                        _ResultObjects.Add(b);
                    }
                }
                return _ResultObjects;
            }
        }

        public List<GameRequest> RequestObjects
        {
            get
            {
                if (_RequestObjects == null && (Requests != null && Requests.Count > 0))
                {
                    _RequestObjects = new List<GameRequest>();
                    foreach (string ThisString in Requests )
                    {
                        Newtonsoft.Json.Linq.JObject o = JObject.Parse(ThisString);

                        GameRequest b = (GameRequest)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(GameRequest));

                        JValue ThisValue = new JValue(ThisString);
                        _RequestObjects.Add(b);
                    }
                }
                return _RequestObjects;
            }
        }

        public List<GameRequest> ChallengeObjects
        {
            get
            {
                if (_ChallengeObjects == null && (Challenges != null && Challenges.Count > 0))
                {
                    _ChallengeObjects = new List<GameRequest>();
                    foreach (string ThisString in Challenges )
                    {
                        Newtonsoft.Json.Linq.JObject o = JObject.Parse(ThisString);

                        GameRequest b = (GameRequest)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(GameRequest));

                        JValue ThisValue = new JValue(ThisString);
                        _ChallengeObjects.Add(b);
                    }
                }
                return _ChallengeObjects;
            }
        }
    }
}
